import { LogMgr } from "../../../platform/log/LogMgr";
import { BaseCtl } from "../../../platform/ui/BaseCtl";
import { Game_2048_MergeDirection, Game_Levels, Game_Status } from "../../common/enums";
import { Game2048PlayView } from "./Game2048PlayView";
import { LevelScript_2048_0 } from "./level_scripts/LevelScript_2048_0";
import { LevelScript_2048_1 } from "./level_scripts/LevelScript_2048_1";
import { LevelScript_2048 } from "./LevelScript_2048";

export class Game2048Ctl extends BaseCtl<Game2048PlayView>{

    //不同难度使用不同的脚本
    _script:LevelScript_2048
    get script(){
        let level = this.view.level
        let data = this.view.dataModel
        if(level==Game_Levels.Simple){
            data.col = 4
            data.row = 4
            this._script = this.scripts.get(Game_Levels.Simple)
        }
        if(level==Game_Levels.Normal){
            data.col = 5
            data.row = 5
            this._script = this.scripts.get(Game_Levels.Normal)
        }
        return this._script

    }
    scripts:Map<number,LevelScript_2048> = new Map()


    init(): void {
        let data = this.view.dataModel
        if(this.scripts.size===0){
            this.scripts.set(Game_Levels.Simple,new LevelScript_2048_0(data))
            this.scripts.set(Game_Levels.Normal,new LevelScript_2048_1(data))
        }  
    }

    //初始化游戏
    initGame(){
        this.script.initGame()
    }

    //开始游戏
    startGame(){
        this.script.startGame()
    }

    //暂停游戏 
    pauseGame(){
        this.script.pauseGame()
    }

    //继续游戏
    reuseGame(){
        this.script.reuseGame()
    }

    //结束游戏
    endGame(){
        this.script.endGame()
    }


    merge(direction: number) {
        return this.script.merge(direction);
    }




    isEnd() {
        //检测有没有1024，有的话解锁下一关

        //没有可合成的则结束
        for (let index = 0; index < 4; index++) {
            
        }
        return false
    }
}